module.exports = function() {
    //start redis client
    var redis = require('redis');
    var redisClient = redis.createClient();
    //要侦听的配置文件,管道名和处理文件名
    var notifyConfig = [{
        channel: "metroProjects:newDataUpload",
        handler: "handler/newDataUpload"
    }];

    //遍历配置文件,侦听所有管道上的消息
    notifyConfig.forEach(function(item) {
        redisClient.subscribe(item.channel);
    });

    //当消息来临时,获取对应的处理文件,处理消息
    redisClient.on('message', function(channel, data) {
        var items = notifyConfig.filter(function(item) {
            return item.channel == channel;
        });
        if (items.length === 0) return;
        var handler = require('./' + items[0].handler + '.js');
        var obj = JSON.parse(data);
        handler(obj);
    });
};
